package com.qianfeng.tools;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;

public class Utils {

	// 格式化日期以Date.toString()为参数类型获取日期(*月*日)
	public static String parseDateGetDate(String date) {
		StringBuffer back = new StringBuffer();
		if (date != null) {
			String[] data = date.split(" ");
			if ("Jan".equals(data[1])) {
				back.append("1");
			} else if ("Feb".equals(data[1])) {
				back.append("2");
			} else if ("Mar".equals(data[1])) {
				back.append("3");
			} else if ("Apr".equals(data[1])) {
				back.append("4");
			} else if ("May".equals(data[1])) {
				back.append("5");
			} else if ("Jun".equals(data[1])) {
				back.append("6");
			} else if ("Jul".equals(data[1])) {
				back.append("7");
			} else if ("Aug".equals(data[1])) {
				back.append("8");
			} else if ("Sep".equals(data[1])) {
				back.append("9");
			} else if ("Oct".equals(data[1])) {
				back.append("10");
			} else if ("Nov".equals(data[1])) {
				back.append("11");
			} else if ("Dec".equals(data[1])) {
				back.append("12");
			}
			back.append("月" + data[2] + "日");
		}
		return back.toString();
	}

	// 格式化日期以Date.toString()为参数类型获取周
	public static String parseDateGetWeek(String date) {
		StringBuffer back = new StringBuffer();
		back.append("星期");
		if (date != null) {
			String[] data = date.split(" ");
			if ("Sun".equals(data[0])) {
				back.append("日");
			} else if ("Mon".equals(data[0])) {
				back.append("一");
			} else if ("Tue".equals(data[0])) {
				back.append("二");
			} else if ("Wed".equals(data[0])) {
				back.append("三");
			} else if ("Thu".equals(data[0])) {
				back.append("四");
			} else if ("Fri".equals(data[0])) {
				back.append("五");
			} else if ("Sat".equals(data[0])) {
				back.append("六");
			}
		}
		return back.toString();
	}

	
	/**
	 * 检测是否有网络
	 * @param context
	 * @return
	 * http://blog.csdn.net/chenzheng_java/article/details/6387116/
	 */
	public static boolean checkNetworkConnection(Context context) {
		boolean flag = false;
		ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		if (wifi != null && wifi.isConnectedOrConnecting()) {
			flag = true;
		} else if (mobile != null && mobile.isConnectedOrConnecting()) {
			flag = true;
		}
		return flag;
	}
	
	// 判断是否挂载存储卡
	public static boolean isSdCardExist() {

		if (Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED)) {// 判断是否已经挂载
			return true;
		}
		return false;
	}

}
